package com.gz.im.backend.component.manage;

import com.corundumstudio.socketio.SocketIOClient;
import com.gz.im.backend.pojo.Agent;
import com.gz.im.backend.pojo.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author GuoZhong
 * @description 本地缓存管理器
 * @date 2023/3/29 23:03
 */
@Component
@RequiredArgsConstructor
public class LocalCacheManage {
	/**
	 *  访客缓存
	 */
	Map<Long, User> userCacheMap = new ConcurrentHashMap<>();

	/**
	 *  坐席缓存
	 */
	Map<Long, SocketIOClient> agentCacheMap = new ConcurrentHashMap<>();

	/**
	 *  redis 监听缓存
	 */
	Map<Long, Integer>  redisListenCacheMap = new ConcurrentHashMap<>();

	/**
	 *  访客与坐席
	 */
	Map<Long, Long>  userAgentCacheMap = new ConcurrentHashMap<>();

	/**
	 *  put 访客
	 */
	public void putUser(Long uid, User user){
		userCacheMap.put(uid,user);
	}
	/**
	 *  get 访客
	 */
	public User getUser(Long uid){
		return userCacheMap.get(uid);
	}
	/**
	 *  rm 访客
	 */
	public void rmUser(Long uid){
		userCacheMap.remove(uid);
	}

	/**
	 *  put 坐席
	 */
	public void putAgent(Long uid, SocketIOClient agent){
		agentCacheMap.put(uid,agent);
	}
	/**
	 *  get 坐席
	 */
	public SocketIOClient getAgent(Long uid){
		return agentCacheMap.get(uid);
	}
	/**
	 *  rm 坐席
	 */
	public void rmAgent(Long uid){
		agentCacheMap.remove(uid);
	}

	/**
	 *  put redis 监听缓存
	 */
	public void putListen(Long uid, Integer agent){
		redisListenCacheMap.put(uid,agent);
	}
	/**
	 *  rm redis 监听缓存
	 */
	public void rmListen(Long uid){
		redisListenCacheMap.remove(uid);
	}
	/**
	 *  访客与坐席id
	 */
	public void putUserAgent(Long uid, Long agentId){
		userAgentCacheMap.put(uid,agentId);
	}
	/**
	 *  访客与坐席id
	 */
	public Long getUserAgent(Long uid){
		return userAgentCacheMap.get(uid);
	}
	/**
	 *  访客与坐席id
	 */
	public void rmUserAgent(Long uid){
		userAgentCacheMap.remove(uid);
	}
}
